public with sharing class QuotesEXT 
{
	List<quote__c> quotes;
	public string filters {get;set;}
	public string pageNumbers;		
	public datetime dateFilter;
	public string whereClause = '';
	public string queryString = 'Select Id, Name, Agent__c, Agent__r.Name, Client_First_Name__c, Client_Last_Name__c, Rate_Type__c, State__c From Quote__c ';
	public string queryEnd = ' ';
	
	//Pagination Variables
   	private integer counter=0;  //keeps track of the offset
   	private integer list_size=30; //sets the page size or number of rows
   	public integer total_size; //used to show user the total size of the list	
   	
   	public string getpageNumbers()
   	{
   		/*Integer pageCounter;
   		integer totalPages = (total_size/30);
   		decimal totalPagesDec = (total_size/30);
   		
   		//if(totalPagesDec > totalPages)
   		totalPages = totalPages + 1;
   		
   		if(counter == 0)
   		{
   			pageCounter = 1; 
   		}
   		else
   		{
   			pageCounter = (counter/30) + 1;
   		}  		   		
   		
   		pageNumbers = 'Page ' + string.valueOf(pageCounter) + ' of ' + string.valueOf(totalPages);   	
   		*/	
   		return pageNumbers;
   	}   		

	public quotesEXT(ApexPages.StandardController controller)
	{
		total_size = [select count() from Quote__c]; //set the total size in the constructor	
	} 
	
   	public PageReference newLink()
   	{
     	return new PageReference('/agent/apex/vfNewQuote');
	}		

        public PageReference test() {
            return null;
        }
	
	public List<SelectOption> getFilter()
	{
		List<SelectOption> options = new List<SelectOption>();
		options.add(new SelectOption('All', 'All'));
		options.add(new SelectOption('Last 90 Days', 'Last 90 Days'));
		return options;
	}
	
	public String getFilters()
	{
		return filters;
	}
	
	public void setFilters(String filters)
	{
		this.filters = filters;
	}

	//Pagination 
   public Quote__c [] getquotes() {
      try {	      	
      	
		if(filters == 'Last 90 Days')
		{
			whereClause = 'Where CreatedDate = Last_90_Days';
		}
		
		queryEnd = 'Order by Name Limit ' + list_size + ' offset ' + counter;		
						
		if(filters == 'All')
		{
			quotes = database.query(queryString + ' ' + queryEnd);
		}
		else
		{
			quotes = database.query(queryString + ' ' + whereClause + ' ' + queryEnd);
		}		
		
		return quotes;
		      	
      }
		catch (QueryException e) {
         ApexPages.addMessages(e);   
         return null;
      }
   }     
       
   public PageReference Beginning() { //user clicked beginning
      counter = 0;
      return null;
   }
 
   public PageReference Previous() { //user clicked previous button
      counter -= list_size;
      return null;
   }
 
   public PageReference Next() { //user clicked next button
      counter += list_size;
      return null;
   }
 
   public PageReference End() { //user clicked end
      counter = total_size - math.mod(total_size, list_size);
      return null;
   }
 
   public Boolean getDisablePrevious() { 
      //this will disable the previous and beginning buttons
      if (counter>0) return false; else return true;
   }
 
   public Boolean getDisableNext() { //this will disable the next and end buttons
      if (counter + list_size < total_size) return false; else return true;
   }
 
   public Integer getTotal_size() {
      return total_size;
   }
 
   public Integer getPageNumber() {
      return counter/list_size + 1;
   }
 
   public Integer getTotalPages() {
      if (math.mod(total_size, list_size) > 0) {
         return total_size/list_size + 1;
      } else {
         return (total_size/list_size);
      }
   }
   
   public void inflateTest() 
   {
       Integer j = 0;
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;    
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;    
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;          
	j++;
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;    
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;
    j++; 
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;    
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;
    j++;
    j++; 
   }	
}